// pages/add_express_numbers/index.js
import {
    getNavigationbar
} from "../../api/index.js"
Page({
    options: {
        styleIsolation: "shared"
    },
    /**
     * 页面的初始数据
     */
    data: {
        logistic: '',
        goodsList: [{
            goodsImg: "/images/element_christmas_xpzq@2x.png",
            goodsName: "商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称",
            goodsPrice: "310.00",
            goodsSpecs: "规格规格规格个规格规格规格规格规格规格个规格规格规格 ",
            goodsSpecsCount: 2,
            details: {
                obj: {
                    name: '',
                   
                },
                shipping_id:''
            },
            text: '',
            ageddress: '商家未配置收货地址，请联系客服',
        }],
    },
    onPullDown() {
        let objStr = JSON.stringify(this.data.details);
        wx.redirectTo({
            url: '/pages/delivery_type/index?data=' + objStr,
        })
    },
    getorderrefund() {
        getNavigationbar({
            act: 'order_refund_detail',
            id: this.data.details.id || '',

        }).then(res => {

            console.log('地址', res)
            let ageddress = res.agent_address
            let text = ''
            if(res.agent_address.name == '') {
                text = '商家未配置收货地址，请联系客服'
            }else {
                text = ageddress.name + ageddress.phone + ageddress.provincename + ageddress.cityname + ageddress.towname + ageddress.address 
            }
            this.setData({
                ageddress: text,

            })
        })
    },
    onClickLeft() {
        // 假设当前页面是 A，要返回到页面 C
        const pages = getCurrentPages(); // 获取当前页面栈
        const currentPageIndex = pages.findIndex(page => page.route === 'pages/add_express_numbers/index'); // 当前页面在页面栈中的索引
        const targetPageIndex = pages.findIndex(page => page.route === 'pages/order_refund_detail/index'); // 目标页面在页面栈中的索引
        const delta = currentPageIndex - targetPageIndex; // 计算页面数差

        wx.navigateBack({
            delta: delta,
            success: function (res) {
                // 返回成功的回调函数
            },
            fail: function (err) {
                // 返回失败的回调函数
            }
        })
    },
    handleSubmit() {
        let arr = 'add_refund_shipping'
        if(this.data.details.types == 'et' ) {
            arr = 'edit_refund_shipping'
        } 
        getNavigationbar({
            act: arr,
            id: this.data.details.id || '',
            logistics_id: this.data.details.shipping_id ,
            shipping_code: this.data.logistic || '',
        }).then(res => {
            console.log(res)
           
            if (res.result == 101) {
                wx.showModal({
                    title: '',
                    content: res.msg,
                    showCancel: false, // 是否显示取消按钮，设为false表示不显示
                    confirmText: '确定', // 确定按钮的文本
                    success(res) {
                        if (res.confirm) {
                            
                        }
                    }
                });
            } else {
                wx.showModal({
                    title: '',
                    content: '填写成功',
                    showCancel: false, // 是否显示取消按钮，设为false表示不显示
                    confirmText: '确定', // 确定按钮的文本
                    success(res) {
                        if (res.confirm) {
                            wx.navigateBack()

                        }
                    }
                });
            }


        })
    },
    onPullDinp(e) {
        console.log('e', e)
        this.data.logistic = e.detail.value
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('进1', options)
        if (options.data) {
            let params = JSON.parse(options.data)
            this.data.details = {
                ...params
            }
            // this.data.logistic =  params.shipping_code
            console.log('进', params, this.data.details, '==', this.data.details.obj)
            if (this.data.details.obj == undefined) {
                if( this.data.details.types == 'et') {
                    this.setData({
                        // text: '请选择',
                        logistic:params.shipping_code,
                        shopname:params.shipping_name,
                        details: params,
                    })
                }else {
                    this.setData({
                        text: '请选择',
                        // logistic:params.shipping_code,
                        // shopname:params.shopname
                    })
                    this.setData({
                        details: params,
                        // logistic:params.shipping_code
                    })
                }
             
            } else {
                this.data.details.shipping_id = this.data.details.obj.id
                this.data.logistic = this.data.details.obj.code
                this.setData({
                    text: this.data.details.obj.name,
                    details:this.data.details,
                    logistic:params.shipping_code,
                    // shopname:params.shopname
                })
                console.log('ces、', this.data.details)
            }
        //    if
           
            this.getorderrefund()
        } else if (options.obj) {

        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})